from selenium.webdriver.common.by import By
from pages.base_page import Page


class AudioVideoChatPage(Page):
    ele_error = (By.XPATH, '//div[@role="alert"]')
    ele_title = (By.ID, u"page-audioVideoChatConfig-title")
    ele_enable_audio_video_chat = (By.XPATH, u'//span[@data-tag="featureSwitch"]')
    ele_audio_video_config = (By.ID, u'form-audioVideoChatConfig')
    ele_save_button = (By.XPATH, u'//button/span[text()="Save"]/..')

    # no feature
    ele_title_no_feature = (By.ID, u'undefined-title')
    ele_unlock_button = (By.XPATH, u'//button/span[text()="Unlock This Feature"]/..')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_if_audio_video_chat_enable(self):
        fs = self.find_element(*self.ele_enable_audio_video_chat)
        if fs.text == 'OFF':
            self.click(self.ele_enable_audio_video_chat)
        else:
            pass

    def check_audio_video_chat_page_when_has_audio_video_chat_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_audio_video_config).is_enabled()
        self.find_element(*self.ele_save_button).is_enabled()

    def check_audio_video_chat_page_when_no_audio_video_chat_feature(self):
        self.find_element(*self.ele_title_no_feature).is_enabled()
        self.find_element(*self.ele_unlock_button).is_enabled()
